/*
 * GPS.java
 *
 * Created on November 5, 2007, 9:32 PM
 */

package vues;


import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.UIManager;

import controleur.Controleur;


/**
 *
 * @author  chewbie
 */
public class InterfacePrincipale extends javax.swing.JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2134190786574252587L;
	public Controleur controleur;
	
	/** Creates new form GPS 
	 * @param controleur */
	public InterfacePrincipale(Controleur controleur) {
		this.controleur = controleur;
		initComponents();
	}
	
	private void initComponents() {
		// Le look and feel de l'application est choisi en fonction de la plateforme
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			System.err.println("Impossible to load the native look and feel for this platform.");
		}
		
		// Mise en page de la fenetre
		paneOnglets = new javax.swing.JTabbedPane();
		panelConducteur = new javax.swing.JPanel();
		panelConducteur.setLayout(new java.awt.CardLayout());

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		paneOnglets.setName("Conducteur");
		
		// 1. Creation du panel Administration
		panelAdministration = new PanelAdministration(this);
		paneOnglets.addTab("Administration", panelAdministration);
		
		// 2. Cr�ation du panel conducteur
		//  a. Cr�ation du panel des pr�f�rences simples
		this.panelPrefSimples = new PanelPrefSimples(this);
		panelConducteur.add(panelPrefSimples, "card3");
		
		//  b. Cr�ation du panel des pr�f�rences avanc�es
		this.panelPrefAvancees = new PanelPrefAvancees(this);
		this.panelPrefAvancees.setReferencePanelPrefSimples(this.panelPrefSimples);
		this.panelPrefSimples.setReferencePanelPrefAvancees(this.panelPrefAvancees);
		panelConducteur.add(panelPrefAvancees, "card3");
		
		//  c. Cr�ation du panel des pr�f�rences avanc�es
		this.panelNavigation = new PanelNavigation(this);
		panelConducteur.add(panelNavigation, "card4");

		paneOnglets.addTab("Conducteur", panelConducteur);
		
		// 3. Creation du panel reseau
		panelReseau = new PanelReseau(this);
		paneOnglets.addTab("Réseau", panelReseau);

		paneOnglets.getAccessibleContext().setAccessibleName("Conducteur");
		
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(paneOnglets, javax.swing.GroupLayout.PREFERRED_SIZE, 817, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap())
		);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addComponent(paneOnglets, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
						.addContainerGap())
		);
		pack();
		
		this.setLocation(new Point(
				(Toolkit.getDefaultToolkit().getScreenSize().width - this.getSize().width)/2, 
				(Toolkit.getDefaultToolkit().getScreenSize().height - this.getSize().height)/2)); 
		this.setResizable(false);
		this.setTitle("RoadGuide");
	}
	
	// Fonctions pour naviguer dans les onglets et panels
	// Affiche l'�cran pr�f�rences simples
	public void affichePrefSimples(java.awt.event.MouseEvent evt) {
		if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1){
			this.panelNavigation.setVisible(false);
			this.panelPrefAvancees.setVisible(false);
			this.panelPrefSimples.setVisible(true);
		}
	}
	
	// Affiche l'�cran pr�f�rences avanc�es
	public void affichePrefAvancees(java.awt.event.MouseEvent evt) {
		if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1){
			this.panelPrefAvancees.setVisible(true);
			this.panelPrefSimples.setVisible(false);
			this.panelNavigation.setVisible(false);
		}
	}
	
	// Affiche l'�cran de navigation 1
	public void afficheNavigation() {
			this.panelNavigation.setVisible(true);
			this.panelPrefAvancees.setVisible(false);
			this.panelPrefSimples.setVisible(false);
			
			// Lance la navigation
			this.panelNavigation.lanceNavigation();
	}
	
//	public static void main(String args[]) {
//		java.awt.EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				new InterfacePrincipale().setVisible(true);
//			}
//		});
//	}

	// Variables declaration //
	// Fenetre principale
	private javax.swing.JTabbedPane paneOnglets;
	
	// 1. Panel administration
	protected PanelAdministration panelAdministration;
	
	// 2. Panel conducteur
	private javax.swing.JPanel panelConducteur;

	//  a. Panel des pr�f�rences simples
	protected PanelPrefSimples panelPrefSimples;

	//  b. Panel des pr�f�rences avanc�es
	private PanelPrefAvancees panelPrefAvancees;
	
	//  c. Panel de navigation
	protected PanelNavigation panelNavigation;

	// 3. Panel du r�seau
	private PanelReseau panelReseau;

	public PanelAdministration getPanelAdministration() {
		return panelAdministration;
	}

	public PanelNavigation getPanelNavigation() {
		return panelNavigation;
	}

	public void setPanelNavigation(PanelNavigation panelNavigation) {
		this.panelNavigation = panelNavigation;
	}
	
}
